import "@site/src/languages/highlight";

# Path

**Description:**

&emsp;&emsp;Helper class for file path operations.

## getScriptPath

**Type:** Function.

**Description:**

&emsp;&emsp;Gets script running path from a module name.

**Signature:**
```tl
getScriptPath: function(self: Path, moduleName: string): string
```

**Usage:**
```tl
-- in the script entry file named 'init'
local scriptPath = Path:getScriptPath(...)
-- set up the project search paths
Content:insertSearchPath(1, scriptPath)
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| moduleName | string | The input module name. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The module path for script searching. |

## getExt

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT output: txt

**Signature:**
```tl
getExt: function(self: Path, path: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The input file's extension. |

## getPath

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT output: /a/b

**Signature:**
```tl
getPath: function(self: Path, path: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The input file's parent path. |

## getName

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT output: c

**Signature:**
```tl
getName: function(self: Path, path: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The input file's name without extension. |

## getFilename

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT output: c.TXT

**Signature:**
```tl
getFilename: function(self: Path, path: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The input file's name. |

## getRelative

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT, base: /a output: b/c.TXT

**Signature:**
```tl
getRelative: function(self: Path, path: string, base: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |
| base | string | The target file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The relative from input file to target file. |

## replaceExt

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT, lua output: /a/b/c.lua

**Signature:**
```tl
replaceExt: function(self: Path, path: string, newExt: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |
| newExt | string | The new file extention to add to file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The new file path. |

## replaceFilename

**Type:** Function.

**Description:**

&emsp;&emsp;Input: /a/b/c.TXT, d output: /a/b/d.TXT

**Signature:**
```tl
replaceFilename: function(self: Path, path: string, newFile: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| path | string | The input file path. |
| newFile | string | The new filename to replace. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The new file path. |

## __call

**Type:** Metamethod.

**Description:**

&emsp;&emsp;input: a, b, c.TXT output: a/b/c.TXT

**Signature:**
```tl
metamethod __call: function(self: Path, ...: string): string
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| ... | string | The segments to be joined as a new file path. |

**Returns:**

| Return Type | Description |
| --- | --- |
| string | The new file path. |